package uk.ac.cam.juliet.zedcat.client;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;
import java.util.concurrent.BlockingQueue;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author David Piggott
 */
public class FrameViewer extends javax.swing.JFrame implements Runnable {

    private final Pipeline mPipeline;
    private final Configuration mConfiguration;
    private final BlockingQueue<Frame> mInputQueue;
    private final BlockingQueue<Frame> mOutputQueue;
    private final SimpleDateFormat mDateFormat = new SimpleDateFormat("HH:mm:ss");
    private Frame mCurrentFrame;

    public void appendLine(String line) {
        consoleTextArea.append(mDateFormat.format(new Date()) + ": " + line + "\n");
    }

    public void updateFramerate(int fR) {
        framerateLabel.setText("Frame rate: " + Integer.toString(fR) + " FPS");
    }

    public void run() {
        while (true) {
            try {
                mCurrentFrame = mInputQueue.take();
                mOutputQueue.put(mCurrentFrame);
                repaint();
            } catch (InterruptedException e) {
            }
        }
    }

    /** Creates new form FrameViewer */
    public FrameViewer(Pipeline p, Configuration c, BlockingQueue<Frame> iQ, BlockingQueue<Frame> oQ) {
        super("Zedcat Image Processing Client");
        mPipeline = p;
        mConfiguration = c;
        mInputQueue = iQ;
        mOutputQueue = oQ;
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException e) {
        } catch (ClassNotFoundException e) {
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        }
        Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
        setIconImage(icon);
        initComponents();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        aboutFrame = new javax.swing.JFrame("About");
        closeButton = new javax.swing.JButton();
        aboutTextArea = new javax.swing.JTextArea();
        imagePanel = new javax.swing.JPanel();
        backgroundScrollPane = new javax.swing.JScrollPane();
        backgroundPanel = new javax.swing.JPanel() {

            private static final long serialVersionUID = 8818477884211939697L;

            public void paintComponent(Graphics g) {
                Graphics2D g2 = (Graphics2D) g;
                g2.setColor(Color.black);
                g2.fill(getVisibleRect());
                if (mPipeline.getBackground() != null) {
                    int centredOriginX = this.getWidth()/2 - mPipeline.getBackground().getWidth()/2;
                    int centredOriginY = this.getHeight()/2 - mPipeline.getBackground().getHeight()/2;

                    g2.drawImage(mPipeline.getBackground(), null, centredOriginX, centredOriginY);

                    setPreferredSize(new Dimension(mPipeline.getBackground().getWidth(), mPipeline.getBackground().getHeight()));
                    revalidate();
                }
            }
        };
        liveScrollPane = new javax.swing.JScrollPane();
        livePanel = new javax.swing.JPanel() {

            private static final long serialVersionUID = 8818477884211939697L;

            public void paintComponent(Graphics g) {
                Graphics2D g2 = (Graphics2D) g;
                g2.setColor(Color.black);
                g2.fill(getVisibleRect());

                if (mCurrentFrame != null) {
                    int centredOriginX = this.getWidth()/2 - mCurrentFrame.getSourceImage().getWidth()/2;
                    int centredOriginY = this.getHeight()/2 - mCurrentFrame.getSourceImage().getHeight()/2;

                    g2.drawImage(mCurrentFrame.getSourceImage(), null, centredOriginX, centredOriginY);

                    setPreferredSize(new Dimension(mCurrentFrame.getSourceImage().getWidth(), mCurrentFrame.getSourceImage().getHeight()));
                    revalidate();

                    if (mConfiguration.displayForegroundPixels()) {
                        for (Pixel p : mCurrentFrame.getForegroundPixels()) {
                            g2.setColor(Color.red);
                            g2.drawLine(centredOriginX + p.getX(), centredOriginY + p.getY(), centredOriginX + p.getX(), centredOriginY + p.getY());
                        }
                    }

                    if (mConfiguration.displayRegions() || mConfiguration.displayBoundingBoxes()) {
                        for (Region region : mCurrentFrame.getRegions()) {
                            if (mConfiguration.displayRegions()) {
                                g2.setColor(Color.green);
                                for (Pixel p : region) {
                                    g2.drawLine(centredOriginX + p.getX(), centredOriginY + p.getY(), centredOriginX + p.getX(), centredOriginY + p.getY());
                                }
                            }
                            if (mConfiguration.displayBoundingBoxes()) {
                                g2.setColor(Color.blue);
                                g2.draw(new Rectangle(centredOriginX + region.getLocation().x, centredOriginY + region.getLocation().y, region.getLocation().width, region.getLocation().height));
                                g2.draw(new Rectangle(centredOriginX + (int) region.getLocation().getMinX() - 1,
                                    centredOriginY + (int) region.getLocation().getMinY() - 1,
                                    (int) region.getLocation().width + 2,
                                    (int) region.getLocation().height + 2));
                        }
                    }
                }

                if (mConfiguration.displayBoundingBoxes()) {
                    for (Hotspot h : mConfiguration.getHotspots()) {
                        g2.setColor(Color.YELLOW);
                        g2.draw(new Rectangle(centredOriginX + h.x, centredOriginY + h.y, h.width, h.height));
                        g2.draw(new Rectangle(centredOriginX + (int) h.getMinX() - 1,
                            centredOriginY + (int) h.getMinY() - 1,
                            (int) h.width + 2,
                            (int) h.height + 2));
                }
            }
        }
    }
    };
    settingsPanel = new javax.swing.JPanel();
    foregroundPixelsCheckBox = new javax.swing.JCheckBox();
    regionsCheckBox = new javax.swing.JCheckBox();
    boundingBoxesCheckBox = new javax.swing.JCheckBox();
    ignoreDisturbanceCheckBox = new javax.swing.JCheckBox();
    selectiveAdaptationCheckBox = new javax.swing.JCheckBox();
    ignoreOnlyRegionsCheckBox = new javax.swing.JCheckBox();
    backgroundSubtractionThresholdSlider = new javax.swing.JSlider(0, 255, mConfiguration.getSubtractionThreshold());
    backgroundAdaptationRateSlider = new javax.swing.JSlider(0, 100, (int) (mConfiguration.getBackgroundAdaptationRate() * 100));
    minimumRegionSizeSlider = new javax.swing.JSlider(0, 100, (int) (mConfiguration.getMinRegionSize()*10));
    maximumDisturbanceSlider = new javax.swing.JSlider(0, 100, mConfiguration.maxDisturbance());
    messagePanel = new javax.swing.JPanel();
    consoleScrollPane = new javax.swing.JScrollPane();
    consoleTextArea = new javax.swing.JTextArea();
    framerateLabel = new javax.swing.JLabel();
    menuBar = new javax.swing.JMenuBar();
    fileMenu = new javax.swing.JMenu();
    exitMenuItem = new javax.swing.JMenuItem();
    backgroundMenu = new javax.swing.JMenu();
    recaptureBackgroundMenuItem = new javax.swing.JMenuItem();
    helpMenu = new javax.swing.JMenu();
    aboutMenuItem = new javax.swing.JMenuItem();

    aboutFrame.setMinimumSize(new java.awt.Dimension(320, 240));
    aboutFrame.setResizable(false);
    Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
    setIconImage(icon);
    aboutFrame.setLocationRelativeTo(null);

    closeButton.setText("Close");
    closeButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            closeButtonActionPerformed(evt);
        }
    });
    aboutFrame.getContentPane().add(closeButton, java.awt.BorderLayout.SOUTH);

    aboutTextArea.setEditable(false);
    aboutTextArea.setLineWrap(true);
    aboutTextArea.setText("Team Juliet 2010\n\n\"Teach Your Cat to Twitter\"\n\nWeb interface accessible via:\nhttp://www.srcf.ucam.org/juliet");
    aboutTextArea.setWrapStyleWord(true);
    aboutTextArea.setMargin(new java.awt.Insets(5, 5, 5, 5));
    aboutTextArea.setMinimumSize(new java.awt.Dimension(320, 240));
    aboutTextArea.setPreferredSize(new java.awt.Dimension(320, 240));
    aboutFrame.getContentPane().add(aboutTextArea, java.awt.BorderLayout.CENTER);

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    imagePanel.setMinimumSize(new java.awt.Dimension(0, 0));
    imagePanel.setLayout(new java.awt.GridLayout(1, 0));

    backgroundScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Background Image", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

    javax.swing.GroupLayout backgroundPanelLayout = new javax.swing.GroupLayout(backgroundPanel);
    backgroundPanel.setLayout(backgroundPanelLayout);
    backgroundPanelLayout.setHorizontalGroup(
        backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 537, Short.MAX_VALUE)
    );
    backgroundPanelLayout.setVerticalGroup(
        backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 427, Short.MAX_VALUE)
    );

    backgroundScrollPane.setViewportView(backgroundPanel);

    imagePanel.add(backgroundScrollPane);

    liveScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Live Image", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

    javax.swing.GroupLayout livePanelLayout = new javax.swing.GroupLayout(livePanel);
    livePanel.setLayout(livePanelLayout);
    livePanelLayout.setHorizontalGroup(
        livePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 537, Short.MAX_VALUE)
    );
    livePanelLayout.setVerticalGroup(
        livePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 427, Short.MAX_VALUE)
    );

    liveScrollPane.setViewportView(livePanel);

    imagePanel.add(liveScrollPane);

    getContentPane().add(imagePanel, java.awt.BorderLayout.CENTER);

    settingsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Settings", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
    settingsPanel.setLayout(new javax.swing.BoxLayout(settingsPanel, javax.swing.BoxLayout.PAGE_AXIS));

    foregroundPixelsCheckBox.setSelected(mConfiguration.displayForegroundPixels());
    foregroundPixelsCheckBox.setText("Display foreground pixels");
    foregroundPixelsCheckBox.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            foregroundPixelsCheckBoxItemStateChanged(evt);
        }
    });
    settingsPanel.add(foregroundPixelsCheckBox);

    regionsCheckBox.setSelected(mConfiguration.displayRegions());
    regionsCheckBox.setText("Display movement regions");
    regionsCheckBox.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            regionsCheckBoxItemStateChanged(evt);
        }
    });
    settingsPanel.add(regionsCheckBox);

    boundingBoxesCheckBox.setSelected(mConfiguration.displayBoundingBoxes());
    boundingBoxesCheckBox.setText("Display bounding boxes");
    boundingBoxesCheckBox.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            boundingBoxesCheckBoxItemStateChanged(evt);
        }
    });
    settingsPanel.add(boundingBoxesCheckBox);

    ignoreDisturbanceCheckBox.setSelected(mConfiguration.ignoreDisturbance());
    ignoreDisturbanceCheckBox.setText("Ignore disturbance");
    ignoreDisturbanceCheckBox.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            ignoreDisturbanceCheckBoxItemStateChanged(evt);
        }
    });
    settingsPanel.add(ignoreDisturbanceCheckBox);

    selectiveAdaptationCheckBox.setSelected(mConfiguration.selectiveAdaptation());
    selectiveAdaptationCheckBox.setText("Selective adaptation");
    selectiveAdaptationCheckBox.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            selectiveAdaptationCheckBoxItemStateChanged(evt);
        }
    });
    settingsPanel.add(selectiveAdaptationCheckBox);

    selectiveAdaptationCheckBox.setSelected(mConfiguration.ignoreOnlyRegions());
    ignoreOnlyRegionsCheckBox.setText("Select only non-regions");
    ignoreOnlyRegionsCheckBox.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            ignoreOnlyRegionsCheckBoxItemStateChanged(evt);
        }
    });
    settingsPanel.add(ignoreOnlyRegionsCheckBox);

    Hashtable<Integer, JLabel> backgroundSubtractionThresholdSliderLabelTable = new Hashtable<Integer, JLabel>();
    backgroundSubtractionThresholdSliderLabelTable.put(new Integer(0), new JLabel("0"));
    backgroundSubtractionThresholdSliderLabelTable.put(new Integer(255), new JLabel("255"));
    backgroundSubtractionThresholdSlider.setLabelTable(backgroundSubtractionThresholdSliderLabelTable);
    backgroundSubtractionThresholdSlider.setPaintLabels(true);
    backgroundSubtractionThresholdSlider.setBorder(javax.swing.BorderFactory.createTitledBorder("Background subtraction threshold"));
    backgroundSubtractionThresholdSlider.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            backgroundSubtractionThresholdSliderStateChanged(evt);
        }
    });
    settingsPanel.add(backgroundSubtractionThresholdSlider);

    Hashtable<Integer, JLabel> backgroundAdaptationRateSliderLabelTable = new Hashtable<Integer, JLabel>();
    backgroundAdaptationRateSliderLabelTable.put(new Integer(0), new JLabel("0"));
    backgroundAdaptationRateSliderLabelTable.put(new Integer(100), new JLabel("1"));
    backgroundAdaptationRateSlider.setLabelTable(backgroundAdaptationRateSliderLabelTable);
    backgroundAdaptationRateSlider.setPaintLabels(true);
    backgroundAdaptationRateSlider.setBorder(javax.swing.BorderFactory.createTitledBorder("Background adaptation rate"));
    backgroundAdaptationRateSlider.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            backgroundAdaptationRateSliderStateChanged(evt);
        }
    });
    settingsPanel.add(backgroundAdaptationRateSlider);

    Hashtable<Integer, JLabel> minimumRegionSizeSliderLabelTable = new Hashtable<Integer, JLabel>();
    minimumRegionSizeSliderLabelTable.put(new Integer(0), new JLabel("0%"));
    minimumRegionSizeSliderLabelTable.put(new Integer(100), new JLabel("10%"));
    minimumRegionSizeSlider.setLabelTable(minimumRegionSizeSliderLabelTable);
    minimumRegionSizeSlider.setPaintLabels(true);
    minimumRegionSizeSlider.setBorder(javax.swing.BorderFactory.createTitledBorder("Minimum region size"));
    minimumRegionSizeSlider.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            minimumRegionSizeSliderStateChanged(evt);
        }
    });
    settingsPanel.add(minimumRegionSizeSlider);

    Hashtable<Integer, JLabel> maximumDisturbanceSliderLabelTable = new Hashtable<Integer, JLabel>();
    maximumDisturbanceSliderLabelTable.put(new Integer(0), new JLabel("0%"));
    maximumDisturbanceSliderLabelTable.put(new Integer(100), new JLabel("100%"));
    maximumDisturbanceSlider.setLabelTable(maximumDisturbanceSliderLabelTable);
    maximumDisturbanceSlider.setPaintLabels(true);
    maximumDisturbanceSlider.setBorder(javax.swing.BorderFactory.createTitledBorder("Maximum disturbance"));
    maximumDisturbanceSlider.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            maximumDisturbanceSliderStateChanged(evt);
        }
    });
    settingsPanel.add(maximumDisturbanceSlider);

    getContentPane().add(settingsPanel, java.awt.BorderLayout.EAST);

    messagePanel.setLayout(new javax.swing.BoxLayout(messagePanel, javax.swing.BoxLayout.PAGE_AXIS));

    consoleScrollPane.getVerticalScrollBar().addAdjustmentListener(
        new AdjustmentListener(){
            public void adjustmentValueChanged(AdjustmentEvent e){
                consoleTextArea.setCaretPosition(consoleTextArea.getDocument().getLength());
            }
        }
    );
    consoleScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    consoleScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    consoleTextArea.setEditable(false);
    consoleTextArea.setRows(8);
    consoleScrollPane.setViewportView(consoleTextArea);

    messagePanel.add(consoleScrollPane);
    messagePanel.add(framerateLabel);

    getContentPane().add(messagePanel, java.awt.BorderLayout.SOUTH);

    fileMenu.setText("File");

    exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
    exitMenuItem.setText("Exit");
    exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            exitMenuItemActionPerformed(evt);
        }
    });
    fileMenu.add(exitMenuItem);

    menuBar.add(fileMenu);

    backgroundMenu.setText("Background");

    recaptureBackgroundMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
    recaptureBackgroundMenuItem.setText("Recapture background");
    recaptureBackgroundMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            recaptureBackgroundMenuItemActionPerformed(evt);
        }
    });
    backgroundMenu.add(recaptureBackgroundMenuItem);

    menuBar.add(backgroundMenu);

    helpMenu.setText("Help");

    aboutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
    aboutMenuItem.setText("About");
    aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            aboutMenuItemActionPerformed(evt);
        }
    });
    helpMenu.add(aboutMenuItem);

    menuBar.add(helpMenu);

    setJMenuBar(menuBar);

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        aboutFrame.setVisible(true);
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void recaptureBackgroundMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_recaptureBackgroundMenuItemActionPerformed
        mPipeline.setBackground();
    }//GEN-LAST:event_recaptureBackgroundMenuItemActionPerformed

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        aboutFrame.setVisible(false);
    }//GEN-LAST:event_closeButtonActionPerformed

    private void regionsCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_regionsCheckBoxItemStateChanged
        mConfiguration.setSetting("displayRegions", regionsCheckBox.isSelected());
    }//GEN-LAST:event_regionsCheckBoxItemStateChanged

    private void boundingBoxesCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_boundingBoxesCheckBoxItemStateChanged
        mConfiguration.setSetting("displayBoundingBoxes", boundingBoxesCheckBox.isSelected());
    }//GEN-LAST:event_boundingBoxesCheckBoxItemStateChanged

    private void foregroundPixelsCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_foregroundPixelsCheckBoxItemStateChanged
        mConfiguration.setSetting("displayForegroundPixels", foregroundPixelsCheckBox.isSelected());
    }//GEN-LAST:event_foregroundPixelsCheckBoxItemStateChanged

    private void ignoreDisturbanceCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_ignoreDisturbanceCheckBoxItemStateChanged
        mConfiguration.setSetting("ignoreDisturbance", ignoreDisturbanceCheckBox.isSelected());
}//GEN-LAST:event_ignoreDisturbanceCheckBoxItemStateChanged

    private void selectiveAdaptationCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_selectiveAdaptationCheckBoxItemStateChanged
        mConfiguration.setSetting("selectiveAdaptation", selectiveAdaptationCheckBox.isSelected());
}//GEN-LAST:event_selectiveAdaptationCheckBoxItemStateChanged

    private void minimumRegionSizeSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_minimumRegionSizeSliderStateChanged
        mConfiguration.setSetting("minRegionSize", (float) (minimumRegionSizeSlider.getValue() / 10));
    }//GEN-LAST:event_minimumRegionSizeSliderStateChanged

    private void maximumDisturbanceSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_maximumDisturbanceSliderStateChanged
        mConfiguration.setSetting("maxDisturbance", maximumDisturbanceSlider.getValue());
    }//GEN-LAST:event_maximumDisturbanceSliderStateChanged

    private void backgroundSubtractionThresholdSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_backgroundSubtractionThresholdSliderStateChanged
         mConfiguration.setSetting("subtractionThreshold", backgroundSubtractionThresholdSlider.getValue());
    }//GEN-LAST:event_backgroundSubtractionThresholdSliderStateChanged

    private void backgroundAdaptationRateSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_backgroundAdaptationRateSliderStateChanged
        mConfiguration.setSetting("backgroundAdaptationRate", ((float) backgroundAdaptationRateSlider.getValue() / (float) 100));
    }//GEN-LAST:event_backgroundAdaptationRateSliderStateChanged

    private void ignoreOnlyRegionsCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_ignoreOnlyRegionsCheckBoxItemStateChanged
        mConfiguration.setSetting("ignoreOnlyRegions", ignoreOnlyRegionsCheckBox.isSelected());
    }//GEN-LAST:event_ignoreOnlyRegionsCheckBoxItemStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    javax.swing.JFrame aboutFrame;
    javax.swing.JMenuItem aboutMenuItem;
    javax.swing.JTextArea aboutTextArea;
    javax.swing.JSlider backgroundAdaptationRateSlider;
    javax.swing.JMenu backgroundMenu;
    javax.swing.JPanel backgroundPanel;
    javax.swing.JScrollPane backgroundScrollPane;
    javax.swing.JSlider backgroundSubtractionThresholdSlider;
    javax.swing.JCheckBox boundingBoxesCheckBox;
    javax.swing.JButton closeButton;
    javax.swing.JScrollPane consoleScrollPane;
    javax.swing.JTextArea consoleTextArea;
    javax.swing.JMenuItem exitMenuItem;
    javax.swing.JMenu fileMenu;
    javax.swing.JCheckBox foregroundPixelsCheckBox;
    javax.swing.JLabel framerateLabel;
    javax.swing.JMenu helpMenu;
    javax.swing.JCheckBox ignoreDisturbanceCheckBox;
    javax.swing.JCheckBox ignoreOnlyRegionsCheckBox;
    javax.swing.JPanel imagePanel;
    javax.swing.JPanel livePanel;
    javax.swing.JScrollPane liveScrollPane;
    javax.swing.JSlider maximumDisturbanceSlider;
    javax.swing.JMenuBar menuBar;
    javax.swing.JPanel messagePanel;
    javax.swing.JSlider minimumRegionSizeSlider;
    javax.swing.JMenuItem recaptureBackgroundMenuItem;
    javax.swing.JCheckBox regionsCheckBox;
    javax.swing.JCheckBox selectiveAdaptationCheckBox;
    javax.swing.JPanel settingsPanel;
    // End of variables declaration//GEN-END:variables
}
